﻿@model YiYiTong.Rocket.Model.Manager.EditPwdReqModel
@{
    ViewBag.Title = "修改密码";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<form action="@Url.Action("EditSelfPwd","User")" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="2">
                <h5>修改密码，标<em>*</em>号是必填或必选项。</h5>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">新密码<em>*</em></td>
            <td><input type="password" id="NewPwd" name="NewPwd" /></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">确认新密码<em>*</em></td>
            <td><input type="password" id="NewAgainPwd" name="NewAgainPwd" /></td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button>
            </td>
        </tr>
    </table>
    <script>
        BUI.use('bui/overlay', function (overlay) {
            function showSucc(obj, url) {
                BUI.Message.Alert(obj, function () {
                    top.location.href = url;
                }, 'success');
            }

            $(function () {
                //判断只能字母,数字,.符号,_下划线或-杠
                jQuery.validator.addMethod("IsPwd", function (value, element) {
                    return this.optional(element) || /^(\d|[a-zA-Z\.\_\-])+$/.test(value);
                }, "只能字母,数字,.符号,_下划线或-杠的组合");

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        NewPwd: { required: true, rangelength: [6, 20], IsPwd: true },
                        NewAgainPwd: { required: true, equalTo: '#NewPwd', IsPwd: true }
                    },
                    messages: {
                        NewPwd: { required: "新密码不能为空", rangelength: "新密码6-20个字符", IsPwd: "只能字母,数字,[.符号],[_下划线]或[-杠]的组合" },
                        NewAgainPwd: { required: "确认新密码不能为空", equalTo: "新密码不一致", IsPwd: "只能字母,数字,[.符号],[_下划线]或[-杠]的组合" }
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            if (result.Message != undefined) {
                                if (result.IsSuccess) {
                                    showSucc(result.Message, result.Body);
                                }
                                else {
                                    $("#spMsg").html(result.Message);
                                }
                                return false;
                            }
                            else {
                                var substr = cutstr(result, "BUI.Message.Alert", "function");
                                substr = substr.replace("'", "").replace("'", "").replace("(", "").replace(",", "");
                                if (substr == "")
                                    BUI.Message.Alert("操作失败，请联系技术人员", 'warning');
                                else {
                                    if (substr.indexOf("请重新登录") > 0) {
                                        BUI.Message.Alert(substr, function () {
                                            top.location.href = "@Url.Action("Login","User")";
                                        }, 'warning');
                                    }
                                    else {
                                        BUI.Message.Alert(substr, 'warning');
                                    }
                                }
                            }
                        });
                    }
                });
            });
        });
    </script>
</form>